<?php
/**
 * Created by PhpStorm.
 * User: JSQ-SL
 * Date: 2018/12/24
 * Time: 11:21
 */

namespace app\index\table;

use think\Db;
use app\index\service\ExcelService;

class StockTypeTable extends BaseTable
{
    protected static $table = 'DICT_STOCK_TYPE';
    protected static $pk = 'TYPE_ID';

    static public function table(){
        return Db::table(static::$table);
    }

    static public function add($data){
        Db::table(static::$table)->insert($data);
    }

    static public function addImport($data){
        Db::table(static::$table)->insert($data);
    }

    static public function update($where,$data){
        Db::table(static::$table)->where($where)->update($data);
    }

    static public function delete($where){
        return Db::table(static::$table)->where($where)->delete();
    }


    public static function exportExcel($data,$fileName){

        $fieldList = [
            ['title'=>'分类号','field'=>'TYPE_ID'],
            ['title'=>'存货分类名称','field'=>'TYPE_NAME'],
            ['title'=>'计量单位','field'=>'UNIT'],
            ['title'=>'库存下限预警','field'=>'LOWER_LIMIT']
        ];

        $excel = new ExcelService();
        $excel->exportExcel($data,$fileName,$fieldList);
    }

    const STOCK_TYPE_FIELD_LIST = [
        "TYPE_ID","TYPE_NAME","UNIT","LOWER_LIMIT"
    ];

}